package logic

import (
	"context"
	"errors"
	"short-video-manager/models/mysql"

	"short-video-manager/videorpc/internal/svc"
	"short-video-manager/videorpc/videorpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CollectDelLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCollectDelLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CollectDelLogic {
	return &CollectDelLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CollectDelLogic) CollectDel(in *videorpc.CollectDelRequest) (*videorpc.CollectDelResponse, error) {
	// todo: add your logic here and delete this line

	var collect mysql.CollectionInfo
	if err := collect.CollectFind(mysql.DB, in); err != nil {
		return nil, errors.New("用户没有权限")
	}
	err := collect.CollectDel(mysql.DB)
	if err != nil {
		return nil, errors.New("删除失败")
	}
	
	return &videorpc.CollectDelResponse{
		CollectId: int64(collect.ID),
	}, nil
}
